<template>
  <el-select v-model="id" placeholder="请选择">
    <el-option
      v-for="item in cities"
      :key="item.id"
      :label="item.name"
      :value="item.id"
    >
      <span style="float: left">{{ item.name }}</span>
      <span style="float: right; color: #8492a6; font-size: 13px">{{
        item.number
      }}</span>
    </el-option>
  </el-select>
</template>

<script>
export default {
  data() {
    return {};
  },
  computed: {
    cities() {
      return this.$store.state.data.coustomerNum;
    },

    id: {
      get: function () {
        return this.$store.state.data.coustomerID;
      },
      set: function (v) {
        this.$store.state.data.coustomerID = v;
      },
    },
  },
  methods: {
    request: async function () {
   
      await this.$axios
        .post("/coustomerrequest", {
          name: this.$store.state.data.coustomerName,
        })
        .then((response) => {
          //客户的id ,编号，名称都获取到
        
        
          this.$store.state.data.coustomerRequest.push(response.data);
          //this.$store.state.data.coustomerNum=response.data

         
          let i;


          
          i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"板子层数：")
            
          if(this.$store.state.data.coustomerRequest[0]){
              //客户是否有铜箔厚度固定属性
              if(this.$store.state.data.coustomerRequest[0].pcbLayer){
                //如果有就调用数据库里面的属性
                this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].pcbLayer
              }else{
                //没有就调用DATA里面的默认属性
                this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.pcbLayer
              }
          }else{
                this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.pcbLayer
              }

          i = this.$myF.arrIndex(this.$store.state.data.pcbInfo, "制板要求：");
          if (this.$store.state.data.coustomerRequest[0]) {
            if (this.$store.state.data.coustomerRequest[0].reqiest) {
              //  this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].reqiest.join(";")
              this.$store.state.data.pcbInfo[
                i
              ].pcbpara = this.$store.state.data.coustomerRequest[0].reqiest;
            } else {
              this.$store.state.data.pcbInfo[i].pcbpara = "";
            }
          } else {
            this.$store.state.data.pcbInfo[i].pcbpara = "";
          }

               i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"过孔处理：")
              if(this.$store.state.data.coustomerRequest[0]){
                 if(this.$store.state.data.coustomerRequest[0].via){
                  this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].via
                 }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.viaDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.viaDF
                  }


           i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"板内增加生产周期：")
              if(this.$store.state.data.coustomerRequest[0]){
                  if(this.$store.state.data.coustomerRequest[0].period){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].period
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.periodDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.periodDF
                  }
          
             i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"板内增加我司编号：")
              if(this.$store.state.data.coustomerRequest[0]){
                  if(this.$store.state.data.coustomerRequest[0].number){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].number
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.numberDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.numberDF
                  }
          
             i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"表面工艺：")
              if(this.$store.state.data.coustomerRequest[0]){
                  if(this.$store.state.data.coustomerRequest[0].process){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].process
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.processDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.processDF
                  }
             
             i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"阻焊颜色：")
              if(this.$store.state.data.coustomerRequest[0]){
                  if(this.$store.state.data.coustomerRequest[0].maskColor){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].maskColor
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.maskColorDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.maskColorDF
                  }
                //需要修改的属性
                   i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"铜箔厚度：")
              //客户是否有特定的工艺属性
              if(this.$store.state.data.coustomerRequest[0]){
                  //客户是否有铜箔厚度固定属性
                  if(this.$store.state.data.coustomerRequest[0].copper){
                    //如果有就调用数据库里面的属性
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].copper
                  }else{
                    //没有就调用DATA里面的默认属性
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.copperDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.copperDF
                  }


                      
                   i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"板材厚度：")
            
              if(this.$store.state.data.coustomerRequest[0]){
                  //客户是否有铜箔厚度固定属性
                  if(this.$store.state.data.coustomerRequest[0].pcbThickness){
                    //如果有就调用数据库里面的属性
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[0].pcbThickness
                  }else{
                    //没有就调用DATA里面的默认属性
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.pcbThicknessDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.pcbThicknessDF
                  }



        })
        .catch((error) => {
          console.log("错误" + error.message);
        });
    },
  },
  watch: {
    id: function (val) {
      //通过当前选择的ID从客户列表中获取当前ID对应的单位名称
      this.$store.state.data.coustomerRequest = [];
      this.$store.state.data.coustomerName = this.$myF.arrValue(
        val,
        "name",
        this.cities
      );
      //通过当前选择的ID从客户列表中获取当前ID对应的单位的编号

      this.$store.state.data.pcbNum.custId = this.$myF.arrValue(
        val,
        "number",
        this.cities
      );
      //发送ajax请求，从后台获取客户特殊要求

      this.request();

      /*
              
              
              let i
              //查找当选中客户是否有默认要求（通过当前选中的客户名称去store里面查找是否有相同的客户名称，如果有就表示这个客户有特殊要求）
              //this.$store.state.data.coustomerRequest修改为ajax请求的数据，从网络获取
              let index=this.$myF.arrIndex2(this.$store.state.data.coustomerRequest,"name",this.$store.state.data.coustomerName)
       
              
 
              
              
              
              //查找到制板要求： 在信息显示的数组位置
              i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"制板要求：")
              //如果这个客户有默认要求，就进去查找是否有制板要求
              if(index>=0){
                  if(this.$store.state.data.coustomerRequest[index].reqiest){
                  //  this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].reqiest.join(";")
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].reqiest
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=""
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=""
                  }
              
              i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"过孔处理：")
              if(index>=0){
                 if(this.$store.state.data.coustomerRequest[index].via){
                  this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].via
                 }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.viaDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.viaDF
                  }
             
             i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"板内增加生产周期：")
              if(index>=0){
                  if(this.$store.state.data.coustomerRequest[index].period){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].period
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.periodDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.periodDF
                  }
          
             i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"板内增加我司编号：")
              if(index>=0){
                  if(this.$store.state.data.coustomerRequest[index].number){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].number
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.numberDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.numberDF
                  }
          
             i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"表面工艺：")
              if(index>=0){
                  if(this.$store.state.data.coustomerRequest[index].process){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].process
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.processDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.processDF
                  }
             i=this.$myF.arrIndex(this.$store.state.data.pcbInfo,"阻焊颜色：")
              if(index>=0){
                  if(this.$store.state.data.coustomerRequest[index].maskColor){
                    this.$store.state.data.pcbInfo[i].pcbpara = this.$store.state.data.coustomerRequest[index].maskColor
                  }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.maskColorDF
                  }
              }else{
                    this.$store.state.data.pcbInfo[i].pcbpara=this.$store.state.data.maskColorDF
                  }

              */

      //生成客户编号
      this.$store.state.data.pcbInfo[1].pcbpara =
        this.$store.state.data.pcbNum.type +
        this.$store.state.data.pcbNum.custId +
        this.$store.state.data.pcbNum.layer +
        this.$store.state.data.pcbNum.num;
    },
  },
  beforeCreate: function () {
    //发送ajax请求，从后台获取获取客户信息
    this.$axios
      .post("/coutomernum")
      .then((response) => {
        //客户的id ,编号，名称都获取到
        this.$store.state.data.coustomerNum = response.data;
        this.id = 1; //设置默认选择的客户名称，放在这里可以避免刷新的时候显示1
      })
      .catch((error) => {
        console.log("错误" + error.message);
      });
  },

  created: function () {
    //通过ID 这里就是默认的客户单位名称
    this.$store.state.data.coustomerName = this.$myF.arrValue(
      this.id,
      "name",
      this.cities
    );
  },
};
</script>

<style>
.el-select-dropdown .el-select-dropdown__wrap {
  max-height: 674px;
}
</style>